const mysql = require("mysql2");
const {
  APP_DATAHOST,
  APP_USER,
  APP_PASSWORD,
  APP_DATABASE,
  APP_LIMIT,
  APP_DATAPORT,
} = require("./config");

const connect = mysql.createPool({
  host: APP_DATAHOST,
  port: APP_DATAPORT,
  user: APP_USER,
  password: APP_PASSWORD,
  connectionLimit: APP_LIMIT,
  database: APP_DATABASE,
});

connect.getConnection((err, con) => {
  con.connect((err) => {
    if (err) {
      console.log("连接数据库失败");
    } else {
      console.log("连接数据库成功");
    }
  });
});

module.exports = connect.promise();
